/**
 * 
 */
package com.taobao.wolfwolf.hibernate.dao.impl;

import java.util.List;
import com.taobao.wolfwolf.hibernate.dao.ComposeColorDao;
import com.taobao.wolfwolf.hibernate.pojo.Color;
import com.taobao.wolfwolf.hibernate.pojo.ComposeColor;

/**
 * @author Tux
 *
 * 创建时间: 2011-4-29 上午09:45:11
 */
@SuppressWarnings("unchecked")
public class ComposeColorDaoImpl extends BaseDaoImpl implements ComposeColorDao {
	
	public ComposeColor findById(int id) throws Exception {
		return (ComposeColor) getHibernateTemplate().get(ComposeColor.class, id);
	}
	
	public List<ComposeColor> findAll() throws Exception {
		return getHibernateTemplate().loadAll(ComposeColor.class);
	}

	public long getTotal() throws Exception {
		return super.countByCriteria(ComposeColor.class);
	}

	public List<ComposeColor> paging(int page, int limit) throws Exception {
		return super.findByCriteriaByPage(ComposeColor.class, page, limit);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public ComposeColor findColor(Color color) {
		List l = getHibernateTemplate().find("from ComposeColor as c where c.buttom_color.name = ?", color.getName());
//		List l = getHibernateTemplate().loadAll(ComposeColor.class);
		if(!l.isEmpty())
			return (ComposeColor) l.get(0);
		else
			return null;
	}
}
